{layout name="public/layout" /}
{include file='yxnavbar'}


<script type="text/javascript">
    function jump(){
        layer.msg('正在准备下载');
    }
function submitForm(){
    var form = document.getElementById("myform");
    form.submit();
}
</script>
<div class="main">
<!--    <ul class="nav nav-tabs">-->
<!--        <li {if $ac == 'display'}class="active"{/if}><a href="{php echo createWebUrl('bargain',array('themeid'=>$themeid));}" >砍价</a></li>-->
<!--    </ul>-->
    {if $ac == "display" || $ac == "search"}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="{$do}" />
                <input type="hidden" name="ac" value="search" />
                <input type="hidden" name="themeid" value="{$themeid}" />
                <input type="hidden" name="state" value="{$state}" />

                <div class="form-group">
                    <label class="col-xs-12 col-sm-1 col-md-1 control-label">砍价状态</label>
                    <div class="col-sm-9 col-xs-9 col-md-9">
                        <div class="btn-group">
                            {loop $type_options $row}
                            <a href="{php echo createWebUrl('bargain', array('ac'=>'display','status'=>$row['status'],'themeid'=>$themeid));}" class="btn {if $current_status == $row['status']}btn-primary{else}btn-default{/if}">
                                {$row['title']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                    {if count($themelist)>1}
                        <div class="col-xs-2 col-sm-2 col-md-2">
                             <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                                <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                             </select>
                        </div>
                    {else}
                        <input type="hidden" name="themeid" value="{$themeid}" /> 
                    {/if}
                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">浏览时间</label>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        {php echo view_form_field_daterange('createtime', array('start'=>date('Y-m-d H:i:s',$start_day),'end'=>date('Y-m-d H:i:s',$end_day)), true);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键词</label>
                    <div class="col-sm-3 col-xs-3 col-md-3">
                        <input class="form-control" name="order_id" placeholder="输入订单号或微信昵称" type="text" value="{$_P['order_id']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
    {/if}
    {if $ac=="help_gift" || $ac=="help_gift_search"}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="{$do}" />
                <input type="hidden" name="ac" value="help_gift_search" />
                <input type="hidden" name="themeid" value="{$themeid}" />
                <input type="hidden" name="state" value="{$state}" />

                <div class="form-group">
                    {if count($themelist)>1}
                    <div class="col-xs-2 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">状态</label>
                    <div class="col-sm-9 col-xs-9 col-md-9">
                        <div class="btn-group">
                            <a href="{php echo filter_url('state:2');}" class="btn {if $state == 2}btn-primary{else}btn-default{/if}">不限<span style="color: #ff0000">{$all_type_num}</span></a>
                            <a href="{php echo filter_url('state:0');}" class="btn {if $state == 0}btn-primary{else}btn-default{/if}">未填写信息<span style="color: #ff0000">{$not_type_num}</span></a>
                            <a href="{php echo filter_url('state:1');}" class="btn {if $state == 1}btn-primary{else}btn-default{/if}">已填写信息<span style="color: #ff0000">{$has_type_num}</span></a>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">浏览时间</label>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        {php echo view_form_field_daterange('createtime', array('start'=>date('Y-m-d H:i:s',$start_day),'end'=>date('Y-m-d H:i:s',$end_day)), true);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键词</label>
                    <div class="col-sm-3 col-xs-3 col-md-3">
                        <input class="form-control" name="search_data" placeholder="输入{$other_name}或{$other_phone}" type="text" value="{$_P['search_data']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                    <div class="col-sm-5 col-lg-5 col-md-5 col-xs-5">
                        {if $total<=5000}
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出EXCEL">
                        {else}
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出EXCEL(1-5000条)">
                        {/if}
                        {if $total>5000}
                        <input class="btn btn-default" type="submit" name="export_submit2" onclick="jump()" id="export_submit2" value="导出(5001-10000)">
                        {/if}
                        {if $total>10000}
                        <input class="btn btn-default" type="submit" name="export_submit3" onclick="jump()" id="export_submit3" value="导出(10001-15000)">
                        {/if}
                        {if $total>15000}
                        <input class="btn btn-default" type="submit" name="export_submit4" onclick="jump()" id="export_submit4" value="导出(15001-20000)">
                        {/if}
                        {if $total>20000}
                        <input class="btn btn-default" type="submit" name="export_submit5" onclick="jump()" id="export_submit5" value="导出(20001-25000)">
                        {/if}
                        {if $total>25000}
                        <input class="btn btn-default" type="submit" name="export_submit5" onclick="jump()" id="export_submit5" value="导出(25001-30000)">
                        {/if}
                    </div>
                </div>

            </form>
        </div>
    </div>
    {/if}

    <!--  列表框  -->
    {if $ac =='display' || $ac == "search"}
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">用户头像</th>
                        <th style="width: 120px">微信昵称</th>
                        <th style="width: 120px">用户姓名</th>
                        <th style="width: 120px">用户联系方式</th>
                        <th style="width: 100px">订单号</th>
                        <th style="width: 120px">当前砍至金额</th>
                        <th style="width: 100px">创建时间</th>
                        <th style="width: 100px">结束时间</th>
                        <th style="width: 100px">状态</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['be_id']}</td>
                        <td><img src="{$item['avatar']}" style="width: 40px;height: 40px;padding: 1px;"></td>
                        <td>{$item['nickname']}</td>
                        <td>{$item['username']}</td>
                        <td>{$item['mobile']}</td>
                        <td>{$item['order_id']}</td>
                        <td>{$item['remain_amount']}</td>
                        <td>{$item['created_at']}</td>
                        <td>{$item['end_time']}</td>
                        <td>
                            {if $item['status']==2}
                            进行中
                            {elseif $item['status']==1}
                            已完成
                            {elseif $item['status']==3}
                            已过期
                            {else}
                            {/if}
                        </td>
                        <td>
                            <a class="btn btn-primary btn-sm" style="width: 35px" data-type="edit" href="{php echo createWebUrl('bargain', array('ac' =>'detail','themeid'=>$themeid,'be_id'=>$item['be_id']));}"  data-id="{$item['be_id']}"  title="查看帮看记录" data-toggle="tooltip" data-placement="top">
                                <i class="fa fa-pencil-square-o"> </i>
                            </a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {/if}
    {if $ac =='help_gift' || $ac =="help_gift_search"}
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">用户头像</th>
                        <th style="width: 120px">微信昵称</th>
                        <th style="width: 120px">{$other_name}</th>
                        <th style="width: 120px">{$other_phone}</th>
                        <th style="width: 120px">礼品名称</th>
                        <th style="width: 120px">礼品图片</th>
                        <th style="width: 100px">创建时间</th>
                        <th style="width: 100px">更新时间</th>
                        <th style="width: 100px">状态</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['hg_id']}</td>
                        <td><img src="{$item['avatar']}" style="width: 40px;height: 40px;padding: 1px;"></td>
                        <td>{$item['nickname']}</td>
                        <td>{$item['user_name']}</td>
                        <td>{$item['user_mobile']}</td>
                        <td>{$item['g_name']}</td>
                        <td><img src="{$item['g_img']}" style="width: 40px;height: 40px;padding: 1px;"></td>
                        <td>{$item['created_at']}</td>
                        <td>{$item['updated_at']}</td>
                        <td>
                            {if $item['status']==0}
                            <span class="label label-warning">未填写信息</span>
                            {elseif $item['status']==1}
                            <span class="label label-info">已填写信息</span>
                            {else}
                            <span class="label label-success">已核销</span>
                            {/if}
                        </td>
                        <td>{if $item['status']==1}
                            <a class="btn btn-primary btn-sm" style="width: 35px" data-type="edit" onclick="convertBargainGift(this)" data-themeid="{$themeid}"  data-id="{$item['hg_id']}"  title="核销兑换礼品" data-toggle="tooltip" data-placement="top">
                                <i class="fa fa-pencil-square-o"> </i>
                            </a>{/if}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {/if}
    <!--    详情页-->
    {if $ac=='detail'}
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">帮砍序号</th>
                        <th style="width: 120px">用户头像</th>
                        <th style="width: 120px">微信昵称</th>
                        <th style="width: 120px">用户姓名</th>
                        <th style="width: 120px">用户联系方式</th>
                        <th style="width: 100px">帮砍金额</th>
                        <th style="width: 80px">帮砍类型</th>
                        <th style="width: 100px">时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['b_id']}</td>
                        <td><img src="{$item['avatar']}" style="width: 40px;height: 40px;padding: 1px;"></td>
                        <td>{$item['nickname']}</td>
                        <td>{$item['username']}</td>
                        <td>{$item['mobile']}</td>
                        <td>{$item['sub_amount']}</td>
                        <td>
                            {if $item['help_type']=='system'}
                            黄金宝刀
                            {elseif $item['help_type']=='share'}
                            分享好友
                            {elseif $item['help_type']=='share_double'}
                            分享金额翻倍
                            {elseif $item['help_type']=='friend'}
                            好友帮砍
                            {else}
                            {/if}
                        </td>
                        <td>
                            {$item['created_at']}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {/if}
</div>

{if $ac =='display' || $ac == "search"}
{$pager}
{/if}
{if $ac =='detail'}
{$pager}
{/if}
{if $ac=="help_gift" || $ac=="help_gift_search"}
{$pager}
{/if}
<script type="text/javascript">
    $(document).ready(
        function (){
            // //检车后台设置未中奖奖品
            // let has_free = $("#has_free").val();
            // if (!has_free){
            //     layer.msg('后台未设置未中奖奖品');
            // }
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    // 兑换奖品
    function convertBargainGift(e) {
        let hg_id = e.getAttribute("data-id");
        let themeid = e.getAttribute("data-themeid");
        let postUrl = "{php echo createWebUrl('bargain', array('ac' =>'convert_help_gift'));}";
        layer.msg('您确定核销该奖品吗？',{
            btn:['确定','取消'],
            yes:function (index) {
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: {hg_id:hg_id,themeid:themeid},
                    success:function (e) {
                        let res = e.message;
                        let code = res.code;
                        let msg = res.msg;
                        if (code!=200){
                            layer.msg(msg);
                        }else{
                            layer.msg(msg);
                            location.reload();
                        }
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
            }
        });
    }
</script>
